home *** CD-ROM | disk | FTP | other *** search
/ MacGames Sampler / PHT MacGames Bundle.iso / MacSource Folder / Samples from the CD / Editors / emacs / Emacs-1.14b1-sources / sources / unix-emulation-src / stdio-internal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-30  |  1.3 KB  |  63 lines  |  [TEXT/EMAC]

  1. /*
  2.  * Copyright (C) 1993, 1994 Marc Parmet.
  3.  * This file is part of the Macintosh port of GNU Emacs.
  4.  *
  5.  * GNU Emacs is distributed in the hope that it will be useful,
  6.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  8.  * GNU General Public License for more details.
  9.  */
  10.  
  11. #if defined(THINK_C)
  12. #include <MacHeaders>
  13. #else
  14. #include <Types.h>
  15. #include <Memory.h>
  16. #include <Quickdraw.h>
  17. #include <Windows.h>
  18. #include <TextEdit.h>
  19. #endif
  20.  
  21. #include "stdio.h"
  22. #include "errno.h"
  23. #include "unix-constants.h"
  24. #include "unix-types.h"
  25.  
  26. long
  27. fflush_internal(FILE *fp,struct savearea_lomem *lomem)
  28. {
  29.     int n;
  30.     
  31.     if (!fp->base) return 0;
  32.     
  33.     if (fp->flag & _READ) {
  34.         fp->cnt = 0;
  35.         set_errno(fp->err = 0);
  36.         return 0;
  37.     }
  38.     else {
  39.         if (fp->fd < 0) return 0;
  40.         n = read_write_internal(unix_write,fp->fd,(char *)fp->base,fp->cnt,lomem);
  41.         if (n != fp->cnt) {
  42.             set_errno(fp->err = EUNDOC);
  43.             return EOF;
  44.         }
  45.         else {
  46.             set_errno(fp->err = 0);
  47.             fp->cnt = 0;
  48.             return 0;
  49.         }
  50.     }
  51. }
  52.  
  53. void
  54. fclose_internal(FILE *fp,struct savearea_lomem *lomem)
  55. {
  56.     if (fp->flag == 0) return; // Is this statement necessary?
  57.     fflush_internal(fp,lomem);
  58.     if (fp->fd < 0) return;
  59.     close_internal(current_process_index,fp->fd,lomem);
  60.     fp->flag = 0;
  61.     if (fp->base && !fp->external_base) DisposPtr((Ptr)fp->base);
  62. }
  63.